Skip to content

Comments

fix: add timeout mechanism and improve error handling#8

Open
hweeken wants to merge 1 commit intoGuDaStudio:mainfrom
hweeken:fix/timeout-and-auth-check
Open

fix: add timeout mechanism and improve error handling#8
hweeken wants to merge 1 commit intoGuDaStudio:mainfrom
hweeken:fix/timeout-and-auth-check

Conversation

@hweeken
Copy link

@hweeken hweeken commented Dec 25, 2025

Summary

This PR addresses the issues reported in #7, implementing critical fixes to prevent MCP calls from blocking indefinitely and improving error handling.

Changes

1. 🔴 Global Timeout Mechanism (Critical Fix)

  • Added timeout parameter to gemini() tool (default: 300 seconds)
  • New GeminiTimeoutError exception for clear error reporting
  • Timeout check in the main loop of run_shell_command()
  • Proper process termination and cleanup on timeout

Before: MCP call could block forever if Gemini CLI got stuck
After: Call fails gracefully with clear error message after timeout

2. 🔴 Pre-flight Auth Check

  • New check_gemini_auth() function to detect auth issues early
  • Returns clear error message guiding users to run gemini auth login
  • Prevents the repeated browser login popup issue

3. 🟡 Improved Resource Management

  • Bounded queue (maxsize=10000) to prevent memory exhaustion with large outputs
  • Daemon threads for proper cleanup on process exit
  • Better process termination handling with multiple fallback attempts
  • Fixed cmd list mutation bug (now uses copy())

4. 🟢 Code Quality

  • Removed unused imports (uuid, List, Literal, BeforeValidator, os)
  • Limited error message accumulation (max 2000 chars) to prevent memory issues
  • Cleaner code structure and improved docstrings
  • Bumped version to 0.1.1

Testing

The changes have been reviewed by two independent AI code reviewers (Claude Opus 4.5 and OpenAI Codex) who identified the original issues.

Related Issues

Fixes #7


🤖 Generated with Claude Code

## Changes

### 1. Global Timeout Mechanism
- Added `timeout` parameter (default 300 seconds) to prevent infinite blocking
- `GeminiTimeoutError` exception for clear error reporting
- Proper process cleanup on timeout

### 2. Pre-flight Auth Check
- `check_gemini_auth()` function to detect auth issues early
- Clear error message guiding users to run `gemini auth login`

### 3. Improved Resource Management
- Bounded queue (maxsize=10000) to prevent memory issues
- Daemon threads for proper cleanup on exit
- Better process termination handling

### 4. Code Quality
- Removed unused imports (uuid, List, Literal, BeforeValidator, os)
- Fixed cmd list mutation bug (now uses copy())
- Limited error message accumulation (max 2000 chars)
- Bumped version to 0.1.1

Fixes GuDaStudio#7

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 MCP 调用可能无限阻塞 + 认证状态未检测导致反复弹出浏览器登录

1 participant